r  =  [1,  -4,  10,  -16,  15]
r[-1]
r[-2]

r[len(r)  -  1]


#Slicing lists
s  =  [3,  186,  4431,  74400,  1048443]
s[1:3]
s[1:-1]
s[3:] 
s[:3]
s[:]


#Copying lists
t = s
t is s

r = s[:]
r is s
r == s

u = s.copy()
u is s
u==s

v = list(s)
v is s
v==s

#Shallow copies
a  =  [  [1,  2],  [3,  4]  ]
b = a[:]
a is b
a == b

a[0]
b[0]
a[0]  is b[0]
 
a[0]  =  [8,  9]
a[0]
b[0]
 
a[1].append(5)
a[1]
b[1] 
a
b


#Repeating lists
c  =  [21,  37]
d = c * 4
d

[0]  *  9

s  =  [  [-1,  +1]  ]  *  5
s

#Repetition is shallow.
s[2].append(7)
s


#Finding list elements with index()
w  =  "the  quick  brown  fox  jumps  over  the  lazy  dog".split()
w
i  =  w.index('fox')
i
w[i]

w.index('unicorn')


#Membership testing with count() and in
w.count("the")
37  in [1,  78,  9,  37,  34,  53]
78  not in [1,  78,  9,  37,  34,  53]


#Removing list elements by index with del
u = "jackdaws love my big sphinx of quartz".split()
u
del u[3]
u


#list elements by value with remove()
u = "jackdaws love my big sphinx of quartz".split()
u.remove('jackdaws')
u

u = "jackdaws love my big sphinx of quartz".split()
del u[u.index('jackdaws')]
u

u.remove('pyramid')


#Inserting into a list
a  =  'I  accidentally  the  whole  universe'.split()
a
a.insert(2,  "destroyed")
a
'  '.join(a)


#Concatenating lists
m  =  [2,  1,  3]
n  =  [4,  7,  11]
k = m + n
k

k  +=  [18,  29,  47]
k

k.extend([76,  129,  199])
k


#Rearranging list elements
g  =  [1,  11,  21,  1211,  112111]
g.reverse()
g


#The sort() method 
d  =  [5,  17,  41,  29,  71,  149,  3299,  7,  13,  67]
d.sort()
d

d.sort(reverse=True)
d

h  =  'not  perplexing  do  handwriting  family  where  I  illegibly  know  doctors'.split()
h
h.sort(key=len)
h
'  '.join(h)
 

#Out-of-place rearrangement
x  =  [4,  9,  2,  1]
y = sorted(x)
y
x

p  =  [9,  3,  1,  0]
q = reversed(p)
q
list(q)
